package cn.hk.message.controller;


import cn.hk.common.entity.QueryObj;
import cn.hk.common.utils.PageHelpUtil;
import cn.hk.message.domain.Message;
import cn.hk.message.service.MessageCopy20220720Service;
import cn.hk.message.service.MessageService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 消息推送信息表 前端控制器
 * </p>
 *
 * @author xu
 * @since 2023-03-08
 */
@Api("消息服务")
@RestController
@RequestMapping("/messageservice/message")
public class MessageController extends BaseController {

    @Autowired
    private MessageService messageService;

    @Autowired
    private MessageCopy20220720Service messageCopyService;

    /**
     * 获取用户个人信息
     * @param userId
     * @return
     */
    @ApiOperation("用户消息列表")
    @GetMapping("appUserMessageList/{userId}")
    public AjaxResult appUserMessageList(@ApiParam("用户id") @PathVariable Long userId){
        List<Message> appUserMessageList = messageService.getAppUserMessageList(userId);
        return AjaxResult.success().put("item",appUserMessageList);
    }

    /**
     * 获取app主页的消息列表
     * @return
     */
    @ApiOperation("主页消息列表")
    @PostMapping("/indexMessageList")
    public AjaxResult indexMessageList(@RequestBody QueryObj queryObj){
        PageHelpUtil.startPage(queryObj.getPageNum(),queryObj.getPageSize(),queryObj.getOrderByColumn(),queryObj.getIsAsc());
        List<Message> indexMessageList = messageService.getIndexMessageList();
        TableDataInfo tableDataInfo = PageHelpUtil.getDataTable(indexMessageList);
        return AjaxResult.success().put("item",tableDataInfo);
    }

    /**
     * 根据messageId获取message
     */
    @ApiOperation(value = "根据消息id获取消息")
    @GetMapping("/getMessageByMessageId/{messageId}")
    public AjaxResult getMessageByMessageId(@ApiParam("消息id")@PathVariable("messageId") Long  messageId){
        Message messageDetail = messageService.getMessageByMessageId(messageId);
        return AjaxResult.success().put("item",messageDetail);
    }

}

